@extends('layouts.admin')
@section('title')
  <title>商户等级列表页</title>
@endsection
@section('content')
  @include('layouts.left')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
       商户等级列表
        <small>Control panel</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title"><a type="button" class="btn btn-block btn-success" href="{{ url('sclass') }}/create">添加商户等级</a></h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-hover">
                <thead>
                <tr>
                  <th><input type="checkbox" name="" value=""></th>
                  <th>id</th>
                  <th>等级（xx元/年）</th>
                  <th>有效时间(年)</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody class="mparent">
                @foreach($datas as $data)
                <tr >
                  <td><input type="checkbox" value="{{$data['id']}}" name="sclass[]"></td>
                  <td>{{ $data -> id }}</td>
                  <td>{{ $data -> rank }}</td>
                  <td>{{ $data -> effecttime }}</td>
                  <td>　<a href="{{url('sclass')}}/{{ $data -> id }}/edit"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="sclass_delete(this,{{ $data -> id }})"><i class="fa fa-trash-o"></i></a></td>
                </tr>
                @endforeach
                </tbody>

              </table>
            </div>
            <!-- /.box-body -->
          </div>
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <!-- 在这里 写js函数-->
  <script type="text/javascript">
      function sclass_delete(e,id){
          $.ajaxSetup({
              headers:{
                  'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
              }
          });
          var tr = $(e).closest("tr");
          if(confirm("确定要删除此条数据吗？"))
          $.ajax({
              url:"{{ url('sclass') }}/"+id,
              type:"DELETE",
              data:{id:id},
              success:function(data){
                  if(data.status == 'have'){
                      alert(data.msg);
                  }else if(data.status == 'success'){
                      alert(data.msg);
                      tr.remove();

                  }else{
                      alert(data.msg);
                  }
              },
              dataType:'json'
          });
      }
  </script>
@endsection


